*Sum up variables across plants---by Firm, Product, and Measuring Unit
foreach var of varlist f3_q_prod_ijtu f3_q_sale_ijtu f3_q_exp_ijtu f3_prod_ijtu  f3_sale_ijtu f3_prod_p_sale_ijtu f3_q_equiv_prod_ijt f3_q_equiv_sale_ijtu f3_q_equiv_exp_ijtu  {
bys ID_FIRMA N_ID_PRODUCTO year f3_measu: egen double temp = sum(`var')
replace `var' = temp
drop temp
}

*Keep only one observation for Firm, Product, Year, and Measuring Unit
bys ID_FIRMA N_ID_PRODUCTO year f3_measu: gen first = year[_n] ~= year[_n+1]
keep if first == 1
drop first
drop ID_PLANTA

*Sum up Variables Across Measuring Units---Excludes quantity variables not measured in equiv. units
foreach var of varlist  f3_prod_ijtu  f3_sale_ijtu f3_prod_p_sale_ijtu f3_q_equiv_prod_ijt f3_q_equiv_sale_ijtu f3_q_equiv_exp_ijtu   {
bys ID_FIRMA N_ID_PRODUCTO year: egen double temp = sum(`var')
replace `var' = temp
drop temp
}
drop f3_measu_unit_ijtu

*Keep only one observation for Firm, Product, and Year
bys ID_FIRMA N_ID_PRODUCTO year: gen first = year[_n] ~= year[_n+1]
replace first = 1 - first
bys ID_FIRMA N_ID_PRODUCTO year: egen mult_units = sum(first)
replace mult_units = 1 if mult_units ~= 0 & mult_units ~= .
keep if first == 0
drop first

*Generate New Quantity Variables
replace f3_q_prod_ijtu = . if mult_units == 1
replace f3_q_sale_ijtu = . if mult_units == 1
replace f3_q_exp_ijtu = . if mult_units == 1

